﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Management;

namespace Authorization
{
   public class WebAuthorizationErrorEvent : System.Web.Management.WebBaseErrorEvent
   {
       private readonly StringBuilder _eventInfo;

       // Invoked in case of events identified 
       // only by their event code.
       public WebAuthorizationErrorEvent(string msg,
           object eventSource, int eventCode, Exception e)
           :
       base(msg, eventSource, eventCode, e)
       {

           // Perform custom initialization.
           _eventInfo = new StringBuilder();
           _eventInfo.Append(string.Format(
               "Event created at: {0} ", EventTime));
       }


       // Invoked in case of events identified 
       // by their event code.and 
       // related event detailed code.
       public WebAuthorizationErrorEvent(string msg,
           object eventSource, int eventCode,
           int detailedCode, Exception e) :
           base(msg, eventSource,
            eventCode, detailedCode, e)
       {
           // Perform custom initialization.
           _eventInfo = new StringBuilder();
           _eventInfo.Append(string.Format(
               "Event created at: {0} ", EventTime));
       }


       // Raises the SampleWebErrorEvent.
       public override void Raise()
       {
           // Perform custom processing. 
           _eventInfo.Append(string.Format(
               "Event raised at: {0} ", EventTime));

           // Raise the event.
           base.Raise();
       }

       //// Obtains the current request information.
       //public string GetRequestInfo()
       //{
       //    string reqInfo = GetRequestInfo();
       //    return reqInfo;
       //}


       //// Obtains the current thread information.
       //public string GetThreadInfo()
       //{
       //    string threadInfo = GetThreadInfo();
       //    return threadInfo;
       //}


       // Obtains the current process information.
       public string GetProcessInfo()
       {
           string procInfo = GetProcessInfo();
           return procInfo;
       }


       ////Formats Web request event information..
       //public override void FormatCustomEventDetails(
       //    WebEventFormatter formatter)
       //{

       //    base.FormatCustomEventDetails(formatter);


       //    // Add custom data.
       //    formatter.AppendLine("");

       //    formatter.IndentationLevel += 1;
       //    formatter.AppendLine(
       //        "** WebCustomErrorEvent Start **");

       //    formatter.AppendLine(_eventInfo.ToString());

       //    formatter.AppendLine(
       //        "** WebCustomErrorEvent End **");

       //    formatter.IndentationLevel -= 1;



       //}
   }
}
